package com.example.mobile2121606109ycg0514homework1;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private Button btnMainBrowse;
    private TextView tvMainCarParts;
    private Button btnMainDete;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        btnMainBrowse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, CarPartsActivity2.class);
                startActivityForResult(intent, 1);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == RESULT_OK){
            tvMainCarParts.setText(data.getStringExtra("carParts"));
        }
    }

    private void initView() {
        btnMainBrowse = (Button) findViewById(R.id.btnMainBrowse);
        tvMainCarParts = (TextView) findViewById(R.id.tvMainCarParts);
        btnMainDete = (Button) findViewById(R.id.btnMainDete);
    }
}